package main;

import component.Button;
import java.io.IOException;
import java.util.Hashtable;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreNotOpenException;
import sprite.Bird;
import sprite.Building;
import sprite.Opponent;
import sprite.Runner;

public final class MainCanvas extends Canvas
        implements Runnable, CommandListener {

    DevilRun mid;
    private RecordStore rs = null;
    static final String WIN_REC_STORE1 = "TempleRun";
    boolean press_left = false;
    boolean press_right = false;
    boolean soundState = true;
    static final int GameSplash = 1;
    static final int GameMenu = 2;
    static final int GamePlay = 3;
    static final int GameStart = 4;
    static final int GameLoading = 5;
    static final int GameHighScore = 6;
    static final int GameGuideThenPlay = 7;
    static final int GameHelp = 8;
    static final int GameGoing2Over = 9;
    static final int GamePause = 10;
    static final int GameOver = 11;
    static final int GameAbout = 12;
    static final int GameSetting = 13;
    boolean Inner = false;
    int GameScreen;
    int splash_check;
    int mScore;
    int NewScore;
    int mHScore;
    int mMenuSelect;
    float Bg1;
    float Bg2;
    float BGSPEED = 0.04F;//Background speed
    float OPPDIFF = -0.18F;//
    float OPPD1 = 0.05F;
    float Jump = -0.042F;
    float TX = 400.0F;// Width
    float TY = 240.0F;//Height
    Bird[] moBird1;
    Bird[] moBird2;
    Bird[] moBird3;
    Bird[] moDust;
    Building[] moWallBase;
    Building moAir = new Building();
    Opponent[] mOpponent;
    GameCanvas mGame;
    Runner mPlayer = new Runner();
    Display dis;
    Image ImgFont;
    Image[] mTex_Run;
    Image[] mTex_Spider;
    Image[] mTex_Font;
    Image[] mTex_BG;
    Image mTex_WallBase;
    Image mTexMano;
    Image mTex_Background;
    Image mTex_select;
    Image mTex_soundoff;
    Image mTex_helpscr;
    Image[] mTex_Bird3;
    Image[] mTex_Kachra;
    Image[] mTex_Devil;
    Image[] mTex_Opp;
    Image[] mTex_Opp1;
    Image[] mTex_Opp2;
    Image[] mTex_Opp5;
    Image[] mTex_Opp6;
    Image[] mTex_Opp7;
    Image[] mTex_Opp8;
    Image[] mTex_Opp9;
    Image[] mTex_Die;
    Image mTex_Opp3;
    Image mTex_Opp4;
//    Image mTex_back;
    Image mTex_options;
    Image mTex_Aboutus;
    Image mTex_gamepaused;
    Image mTex_gameover;
    Image mTex_Score;
    Image mTex_Pause;
    private int score1;
    public Player[] mp3player;
    static Hashtable configHashTable;
    Button btnStartGame, btnPause, btnBack, btnSetting,
            btnHelp, btnAbout, btnHighScore, btnExit,
            btnSound, btnResume, btnSetting2, btnReset, btnHome;

    public MainCanvas(final DevilRun midlet)
            throws IOException, RecordStoreNotOpenException {
        this.mid = midlet;
        setFullScreenMode(true);
        openRecStore();
        mHScore = readRecords();
        System.out.println("HighScore: " + mHScore);
        GameScreen = MainCanvas.GameSplash;
        TX = getWidth();
        TY = getHeight();
        load();
        try {
            loadSound();
        } catch (Exception e) {
        }
        dis = Display.getDisplay(mid);

        Canvas canvas = new Canvas() {
            protected void paint(Graphics arg0) {
            }
        };
        boolean pointer = canvas.hasPointerEvents();
    }

    void load() throws IOException {
        loadbird();
        loadHuman();
        loadopponent();
        mTex_helpscr = Image.createImage("/uiImage/help.jpg");
        mTex_Background = Image.createImage("/uiImage/splash.jpg");
        mTex_select = Image.createImage("/spriteImage/selection.png");
        mTex_soundoff = Image.createImage("/spriteImage/soff.png");
        mTexMano = Image.createImage("/spriteImage/mano.jpg");
        ImgFont = Image.createImage("/spriteImage/font_strip.png");
        mTex_gamepaused = add("/uiImage/gamepaused.png");
        mTex_gameover = add("/uiImage/gameover.png");
        mTex_Aboutus = add("/uiImage/aboutus.jpg");
        mTex_Score = add("/uiImage/scoreBoard.png");
        mTex_BG = new Image[1];
        mTex_BG[0] = add("/spriteImage/bg.jpg");
        mTex_WallBase = add("/spriteImage/brickwall.png");
        mTex_options = add("/uiImage/options.png");
        mTex_Pause = add("/uiImage/pausede.png");
        mTex_Devil = new Image[6];

        for (int i = 0; i < mTex_Devil.length; i++) {
            mTex_Devil[i] = add("/spriteImage/devil" + i + ".gif");
        }
        moBird1 = new Bird[10];
        for (int i = 0; i < moBird1.length; i++) {
            moBird1[i] = new Bird();
        }
        moBird2 = new Bird[10];
        for (int i = 0; i < moBird2.length; i++) {
            moBird2[i] = new Bird();
        }
        moBird3 = new Bird[10];
        for (int i = 0; i < moBird3.length; i++) {
            moBird3[i] = new Bird();
        }
        moDust = new Bird[10];
        for (int i = 0; i < moDust.length; i++) {
            moDust[i] = new Bird();
        }

        moWallBase = new Building[5];
        for (int i = 0; i < moWallBase.length; i++) {
            moWallBase[i] = new Building();
        }
        mOpponent = new Opponent[10];

        for (int i = 0; i < mOpponent.length; i++) {
            mOpponent[i] = new Opponent();
        }
//        mMenuSelect = 1;

        btnStartGame = new Button("/uiImage/start.png", "/uiImage/startPressing.png", "/uiImage/start.png", "/uiImage/startPressing.png", new Button.Listener() {
            public void clicked(Button button) {
                GameScreen = MainCanvas.GameGuideThenPlay;
            }
        });
        btnStartGame.setPosition(123, 79);
        try {
            btnSetting = new Button("/uiImage/setting.png", "/uiImage/settingPressing.png", "/uiImage/setting.png", "/uiImage/settingPressing.png", new Button.Listener() {
                public void clicked(Button button) {
                    GameScreen = MainCanvas.GameSetting;
                }
            });
        } catch (Exception e) {
            System.out.println("error");
        }
        btnSetting.setPosition(270, 27);

        btnAbout = new Button("/uiImage/about.png", "/uiImage/aboutPressing.png", "/uiImage/about.png", "/uiImage/aboutPressing.png", new Button.Listener() {
            public void clicked(Button button) {
                GameScreen = MainCanvas.GameAbout;
            }
        });

        btnAbout.setPosition(30, 161);

        btnHighScore = new Button("/uiImage/highscore.png", "/uiImage/highscorePressing.png", "/uiImage/highscore.png", "/uiImage/highscorePressing.png", new Button.Listener() {
            public void clicked(Button button) {
                System.out.println("HighScore button clicked");
                GameScreen = MainCanvas.GameHighScore;
            }
        });
        btnHighScore.setPosition(30, 27);

        btnExit = new Button("/uiImage/exit.png", "/uiImage/exitPressing.png", "/uiImage/exit.png", "/uiImage/exitPressing.png", new Button.Listener() {
            public void clicked(Button button) {
                System.out.println("Exit button clicked");
                mid.destroyApp(true);
            }
        });
        btnExit.setPosition(270, 161);

        btnBack = new Button("/uiImage/backde.png", "/uiImage/backde.png", "/uiImage/backde.png", "/uiImage/backde.png", new Button.Listener() {
            public void clicked(Button button) {
                if (Inner) {
                    GameScreen = MainCanvas.GamePause;
                    Inner = false;
                } else {
                    GameScreen = MainCanvas.GameMenu;
                }
            }
        });
        btnBack.setPosition(360, 200);

        btnSound = new Button("/uiImage/switchOn.png", "/uiImage/switchOn.png", "/uiImage/switchOn.png", "/uiImage/switchOff.png", new Button.Listener() {
            public void clicked(Button button) {

                if (soundState == true) {
                    soundState = false;
                    btnSound.setPressed(true);
                } else {
                    soundState = true;
                    btnSound.setPressed(false);
                }
            }
        });
        btnSound.setPosition(100, 60);

        btnResume = new Button("/uiImage/resume.png", "/uiImage/resume.png", "/uiImage/resume.png", "/uiImage/resume.png", new Button.Listener() {
            public void clicked(Button button) {
                GameScreen = MainCanvas.GamePlay;
            }
        });
        btnResume.setPosition(40, 190);

        btnSetting2 = new Button("/uiImage/settinginside.png", "/uiImage/settinginsidePressing.png", "/uiImage/settinginside.png", "/uiImage/settinginside.png", new Button.Listener() {
            public void clicked(Button button) {
                Inner = true;
                GameScreen = MainCanvas.GameSetting;
            }
        });
        btnSetting2.setPosition(160, 190);

        btnReset = new Button("/uiImage/reset.png", "/uiImage/reset.png", "/uiImage/resetPressing.png", "/uiImage/reset.png", new Button.Listener() {
            public void clicked(Button button) {
                reset();
            }
        });
        btnReset.setPosition(40, 190);
        
        btnHome = new Button("/uiImage/home.png", "/uiImage/homePressing.png", "/uiImage/home.png", "/uiImage/home.png", new Button.Listener() {

            public void clicked(Button button) {
                GameScreen = MainCanvas.GameMenu;
            }
        });
        btnHome.setPosition(280, 190);
    }

    void loadbird() {
        mTex_Bird3 = new Image[5];
        Image b = add("/spriteImage/birdwhite.png");
        for (int i = 0; i < mTex_Bird3.length; i++) {
            mTex_Bird3[i] = Image.createImage(b, i * b.getWidth() / mTex_Bird3.length, 0, b.getWidth() / mTex_Bird3.length, b.getHeight(), 0);
        }
        mTex_Kachra = new Image[4];
        for (int i = 0; i < mTex_Kachra.length; i++) {
            mTex_Kachra[i] = add("/spriteImage/dust" + i + ".png");
        }
    }

    void loadSound() throws IOException, MediaException {
        mp3player = new Player[1];
        mp3player[0] = Manager.createPlayer(getClass().getResourceAsStream("/sound/bgsound.amr"), "audio/amr");
    }

    void loadopponent() {
        mTex_Opp = new Image[4];
        mTex_Opp1 = new Image[4];
        mTex_Opp2 = new Image[4];
        mTex_Opp5 = new Image[8];
        mTex_Opp6 = new Image[8];
        mTex_Opp7 = new Image[8];
        mTex_Opp8 = new Image[8];
        mTex_Opp9 = new Image[8];
        mTex_Die = new Image[4];
        Image opp = add("/spriteImage/gear0.png");
        for (int i = 0; i < mTex_Opp.length; i++) {
            mTex_Opp[i] =
                    Image.createImage(opp, i * opp.getWidth() / mTex_Opp.length,
                    0, opp.getWidth() / mTex_Opp.length, opp.getHeight(), 0);
        }
        opp = add("/spriteImage/gear1.png");
        for (int i = 0; i < mTex_Opp.length; i++) {
            mTex_Opp1[i] =
                    Image.createImage(opp, i * opp.getWidth() / mTex_Opp1.length,
                    0, opp.getWidth() / mTex_Opp1.length, opp.getHeight(), 0);
        }
        opp = add("/spriteImage/gear2.png");
        for (int i = 0; i < mTex_Opp.length; i++) {
            mTex_Opp2[i] =
                    Image.createImage(opp, i * opp.getWidth() / mTex_Opp2.length,
                    0, opp.getWidth() / mTex_Opp2.length, opp.getHeight(), 0);
        }
        mTex_Opp3 = add("/spriteImage/gear3.png");
        mTex_Opp4 = add("/spriteImage/gear4.png");

        Image opp5 = add("/spriteImage/gear5.png");
        for (int i = 0; i < mTex_Opp5.length; i++) {
            mTex_Opp5[i] =
                    Image.createImage(opp5, i * opp5.getWidth() / mTex_Opp5.length,
                    0, opp5.getWidth() / mTex_Opp5.length, opp5.getHeight(), 0);
        }
        opp5 = add("/spriteImage/gear6.png");
        for (int i = 0; i < mTex_Opp5.length; i++) {
            mTex_Opp6[i] =
                    Image.createImage(opp5, i * opp5.getWidth() / mTex_Opp6.length,
                    0, opp5.getWidth() / mTex_Opp6.length, opp5.getHeight(), 0);
        }
        opp5 = add("/spriteImage/gear7.png");
        for (int i = 0; i < mTex_Opp5.length; i++) {
            mTex_Opp7[i] =
                    Image.createImage(opp5, i * opp5.getWidth() / mTex_Opp7.length,
                    0, opp5.getWidth() / mTex_Opp7.length, opp5.getHeight(), 0);
        }
        opp5 = add("/spriteImage/gear8.png");
        for (int i = 0; i < mTex_Opp5.length; i++) {
            mTex_Opp8[i] = Image.createImage(opp5, i * opp5.getWidth() / mTex_Opp8.length, 0, opp5.getWidth() / mTex_Opp8.length, opp5.getHeight(), 0);
        }
        opp5 = add("/spriteImage/gear9.png");
        for (int i = 0; i < mTex_Opp5.length; i++) {
            mTex_Opp9[i] = Image.createImage(opp5, i * opp5.getWidth() / mTex_Opp9.length, 0, opp5.getWidth() / mTex_Opp9.length, opp5.getHeight(), 0);
        }
        Image b = add("/spriteImage/fail.png");
        for (int i = 0; i < mTex_Die.length; i++) {
            mTex_Die[i] = Image.createImage(b, i * b.getWidth() / mTex_Die.length, 0, b.getWidth() / mTex_Die.length, b.getHeight(), 0);
        }
    }

    void loadHuman() {
        mTex_Run = new Image[15];
        for (int i = 0; i < mTex_Run.length; i++) {
            mTex_Run[i] = add("/spriteImage/human" + i + ".png");
        }
        mTex_Spider = new Image[6];
        Image b1 = add("/spriteImage/spider.png");
        for (int i = 0; i < mTex_Spider.length; i++) {
            mTex_Spider[i] = Image.createImage(b1, i * b1.getWidth() / mTex_Spider.length, 0, b1.getWidth() / mTex_Spider.length, b1.getHeight(), 0);
        }
    }

    Image add(String ID) {
        try {
            return Image.createImage(ID);
        } catch (Exception e) {
        }
        return null;
    }

    void reset() {
        Bg1 = 0.0F;
        Bg2 = 1.0F;
        if (mHScore < mScore) {
            mHScore = readRecords();
        }
        NewScore = (this.mScore = 0);
        if (mHScore == 0) {
            NewScore += 1;
        }
        BGSPEED = -0.04F;
        GameScreen = MainCanvas.GamePlay;
        //Set Human position by percent
        //x = 30%
        //y = 100%-wall% - %HumanHeight/2
        mPlayer.set(0.3F, 1.0F - mTex_WallBase.getHeight() / TY - mTex_Run[0].getHeight() / TY / 2.0F, 0.0F);
        float y = 0.0F;
        //Set position of wall
        //y = -100% + %wall/2 ||because when draw wallbase in GameCanvas 100% - y 
        y = -1.0F + mTex_WallBase.getHeight() / TY / 2.0F;
        for (int i = 0; i < moWallBase.length; i++) {
            moWallBase[i].set(i * (mTex_WallBase.getWidth() / TX), y, i);
        }
        moAir.set(1.0F, 0.2F, 0);
        for (int i = 0; i < moBird1.length; i++) {
            moBird1[i].set(10.0F, 0.0F, 0.0F, 0.0F, 0);
        }
        for (int i = 0; i < moBird2.length; i++) {
            moBird2[i].set(10.0F, 0.0F, 0.0F, 0.0F, 0);
        }
        for (int i = 0; i < moBird3.length; i++) {
            moBird3[i].set(10.0F, 0.0F, 0.0F, 0.0F, 0);
        }
        long time = System.currentTimeMillis();
        for (int i = 0; i < moDust.length; i++) {
            moDust[i].set(1.0F, 1.0F, -0.1F, -0.1F, (int) (time % 10L % 10L));
            time /= 10L;
        }
        time = System.currentTimeMillis();
        for (int i = 0; i < mOpponent.length; i++) {
            mOpponent[i].set((i + 3) * 1, 1.0F - mTex_WallBase.getHeight() / TY - mTex_Opp[0].getHeight() / TY / 2.0F, Math.abs(i % mOpponent.length), (int) (time % 2L));
            time /= 10L;
        }

        mGame.cnt1 = 0;
        mGame.newScr = 10.0F;
    }

    protected void pointerDragged(int x1, int y1) {
        switch (GameScreen) {
            case MainCanvas.GamePlay:
                mGame.HandleGame(1, x1, y1);
        }
    }

    public void pointerReleased(int x1, int y1) {
        switch (GameScreen) {
            case MainCanvas.GamePause:
                btnResume.pointerReleased(x1, y1);
                btnSetting2.pointerReleased(x1, y1);
                btnHome.pointerReleased(x1, y1);
                break;
            case MainCanvas.GameOver:
                btnReset.pointerReleased(x1, y1);
                btnSetting2.pointerReleased(x1, y1);
                break;
            case MainCanvas.GamePlay:
                mGame.HandleGame(2, x1, y1);
                break;
            case MainCanvas.GameMenu:
                btnStartGame.pointerReleased(x1, y1);
                btnSetting.pointerReleased(x1, y1);
                btnAbout.pointerReleased(x1, y1);
                btnExit.pointerReleased(x1, y1);
                btnHighScore.pointerReleased(x1, y1);
                break;
            case MainCanvas.GameHighScore:
                btnBack.pointerReleased(x1, y1);
                break;
            case MainCanvas.GameHelp:
                mGame.HandleHelp(2, x1, y1);
                break;
            case MainCanvas.GameGuideThenPlay:
                break;
            case MainCanvas.GameSplash:
                GameScreen = MainCanvas.GameMenu;

                break;
            case MainCanvas.GameAbout:
//                mGame.HandleAbout(2, x1, y1);
                btnBack.pointerReleased(x1, y1);
                break;
            case MainCanvas.GameSetting:
                btnSound.pointerReleased(x1, y1);
                btnBack.pointerReleased(x1, y1);
        }
    }

    public void pointerPressed(int x1, int y1) {
        switch (GameScreen) {
            case MainCanvas.GamePause:
                btnResume.pointerPressed(x1, y1);
                btnSetting2.pointerPressed(x1, y1);
                btnHome.pointerPressed(x1, y1);
                break;
            case MainCanvas.GameOver:
                btnReset.pointerPressed(x1, y1);
                btnSetting2.pointerPressed(x1, y1);
                break;
            case MainCanvas.GamePlay:
                mGame.HandleGame(0, x1, y1);
                break;
            case MainCanvas.GameMenu:
                btnStartGame.pointerPressed(x1, y1);
                btnSetting.pointerPressed(x1, y1);
                btnAbout.pointerPressed(x1, y1);
                btnHighScore.pointerPressed(x1, y1);
                btnExit.pointerPressed(x1, y1);
                break;
            case MainCanvas.GameHighScore:
                btnBack.pointerPressed(x1, y1);
                break;
            case MainCanvas.GameHelp:
                mGame.HandleHelp(0, x1, y1);
                break;
            case MainCanvas.GameGuideThenPlay:
                reset();
                break;
            case MainCanvas.GameSplash:
                GameScreen = MainCanvas.GameMenu;
                break;
            case MainCanvas.GameAbout:
                btnBack.pointerPressed(x1, y1);
                break;
            case MainCanvas.GameSetting:
                btnSound.pointerPressed(x1, y1);
                btnBack.pointerPressed(x1, y1);
                break;
            case MainCanvas.GameStart:
            case MainCanvas.GameLoading:
            case MainCanvas.GameGoing2Over:
        }
    }

    void Draw_number(Graphics g, int str, int x, int y) {
        String strs = "" + str;
        for (int i = 0; i < strs.length(); i++) {
            int k = strs.charAt(i);
            g.drawRegion(ImgFont, (k - 48) * ImgFont.getWidth() / 11, 0,
                    ImgFont.getWidth() / 11, ImgFont.getHeight(),
                    0, x + i * ImgFont.getWidth() / 11, y, 0);
        }
    }

    public void paint(Graphics g) {
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, getWidth(), getHeight());
        switch (GameScreen) {
            case MainCanvas.GameSplash:
                drawSplash(g);
                break;
            case MainCanvas.GamePlay:
            case MainCanvas.GameGoing2Over:
                mGame.DrawGamePlay(g);
                break;
            case MainCanvas.GameLoading:
            case MainCanvas.GamePause:
                mGame.DrawGameoverAndPause(g);
                break;
            case MainCanvas.GameOver:
                mGame.DrawGameoverAndPause(g);
                break;
            case MainCanvas.GameMenu:
                mGame.DrawMenu(g);
                break;
            case MainCanvas.GameHighScore:
//                mGame.DrawOption(g);
                g.drawImage(mTex_Background, 0, 0, 20);
                btnBack.paint(g);
                g.drawString("Highscore: ", 20, 96, 20);
                String strs = mHScore + "";
                float dx = strs.length() * (ImgFont.getWidth() / TX / 2.0F);
                Draw_number(g, readRecords(), 100, 100);
                System.out.println("Highscore: " + readRecords());
                break;
            case MainCanvas.GameGuideThenPlay:
            case MainCanvas.GameHelp:
                mGame.DrawHelp(g);
                break;
            case MainCanvas.GameAbout:
                mGame.DrawAbout(g);
                break;
            case MainCanvas.GameSetting:
                g.drawImage(mTex_Background, 0, 0, 20);
                btnSound.paint(g);
                btnBack.paint(g);
                break;
            case MainCanvas.GameStart:

        }

        try {
            if (GameScreen == MainCanvas.GameSplash) {
                Thread.sleep(50L);
                try {
                    mGame = new GameCanvas(this);
                } catch (IOException ex) {
                }
                splash_check += 1;
                if (splash_check > 50) {
                    GameScreen = MainCanvas.GameMenu;
                }
            } else {
                Thread.sleep(25);
            }
        } catch (InterruptedException ex) {
        }
        repaint();
    }

    public void run() {
        try {
            Thread.sleep(0L);
            repaint();
        } catch (InterruptedException ex) {
        }
    }

    public void drawSplash(Graphics g) {
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.drawImage(mTexMano, getWidth() / 2, getHeight() / 2, 3);
    }



    public void Soundplay(int i) {
        i = 0;
        try {
            if (soundState) {
                if (i == 0) {
                    mp3player[i].realize();
                    mp3player[i].prefetch();
                }
                mp3player[i].start();
                if (i == 0) {
                    mp3player[i].setLoopCount(-1);
                }
//                System.out.println(soundState + "~~~~~~~~~~~~~~~" + i);
            }
        } catch (Exception e) {
//            System.out.println(soundState + "~~~~~~~*********~~~~~~~~" + i);
        }
    }

    public void soundstop(int i) {
        i = 0;
        try {
            mp3player[i].stop();
        } catch (Exception e) {
        }
    }

    public int readRecords() {
        try {
            byte[] recData = new byte[5];

            for (int i = 1; i <= rs.getNumRecords(); i++) {
                if (rs.getRecordSize(i) > recData.length) {
                    recData = new byte[rs.getRecordSize(i)];
                }
                int len = rs.getRecord(i, recData, 0);
                int highscore = Integer.parseInt(new String(recData, 0, len));
                score1 = highscore;
            }
        } catch (Exception e) {
        }

        return score1;
    }

    public void WinnerScore() {
        if (mScore > readRecords()) {
            deleteRecStore();
            writeRecord(mScore + "");
        }
    }

    public void openRecStore() {
        try {
            rs = RecordStore.openRecordStore("TempleRun", true);
        } catch (Exception e) {
        }
    }

    public void deleteRecStore() {
        if (RecordStore.listRecordStores() != null) {
            try {
                RecordStore.deleteRecordStore("TempleRun");
            } catch (Exception e) {
            }
        }
    }

    public void writeRecord(String str) {
        byte[] rec = str.getBytes();
        try {
            rs.addRecord(rec, 0, rec.length);
        } catch (Exception e) {
        }
    }

    public void commandAction(Command c, Displayable d) {
    }
}
